package aima.search;

import java.lang.*;
import java.util.*;
import aima.cs.util.*;

/**
   This class implements a general queue search.
*/ 

public class GeneralQueueSearch implements SearchMethod {

/** Queue for search */
   protected GeneralQueue Q; 

/**
   Constructor takes an initial search node, and a search queue.  
   Specific searches can be instantiated by choosing specific queues 
   in the constructor.
*/
   public GeneralQueueSearch(SearchNode startNode, GeneralQueue Q) {
         this.Q = Q; 
         Q.add( startNode );
   }

/**
   Implementation of general queue search.
*/
   public SearchNode search() {

      while (!Q.isEmpty()) {

         SearchNode expandNode = (SearchNode) Q.removeFront();
         if (expandNode.getState().isGoal()) {
             return expandNode;
         } else {
             expandNode.expand(Q);
         } 

      }

      return null;

   } 

}

